package com.hqq.exercise.cal;

/**
 * AddWithoutOps 不用加减乘除做加法
 * 题目描述:
 * 写一个函数，求两个整数之和，要求在函数体内不得使用+、-、*、/四则运算符号
 * Created by heqianqian on 2017/8/23.
 */
public class AddWithoutOps {

    public static void main(String[] args) {
        int result = add(19, 27);
        System.out.println(result);
    }

    public static int add(int m, int n) {
        int sum = 0, carry;
        while (n!=0){
            sum = m ^ n;
            carry = (m & n) << 1;
            m = sum;
            n = carry;
        }
        return sum;
    }
}
